package com.hyper_yang._05_juc.chap01;

/**
 * 线程创建几种方式：
 * 1.继承Thread
 * 2.实现Runnable
 * 3.实现Callable
 * 4.线程池
 */
public class ThreadDemo {
    public static void main(String[] args) {
//        T1 t1 = new T1();
//        t1.setName("t1");
//        t1.start();
//        t1.start(); ==> 已经激活了 RUNNABLE，再次 start(): illegalThreadStateException

//        T2 t2 = new T2();
//        Thread thread1 = new Thread(t2); // 构造器接收 runnable参数
//        thread1.setName("t2");
//        thread1.start(); // 线程6个状态
//        //thread1.start(); //java.lang.IllegalThreadStateException

//        new Thread(new Runnable() { //匿名内部类
//            @Override
//            public void run() {
//                System.out.println(Thread.currentThread().getName() + " inner class runnable - run ... ");
//            }
//        },"t3").start();

        //函数式接口 -> lambada表达式形式。
        new Thread(() -> System.out.println(Thread.currentThread().getName() + " lambada class runnable - run ... "), "t4").start();

    }
}

//1.继承Thread
class T1 extends Thread {
    @Override
    public void run() {
        System.out.println("T1 - run ... ");
    }
}

//2.实现Runnable
class T2 implements Runnable {
    @Override
    public void run() {
        System.out.println("T2 - run ... ");
    }
}



